package org.springblade.modules.notice.core.conditon;

import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.modules.notice.core.conditon.impl.*;
import org.springblade.modules.notice.enums.TriggerConditionEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author ysq
 * @Date 2024/12/06
 * @Description 触发条件策略
 */
public class TriggerConditionStrategy {

	private static Map<Integer, TriggerConditionFactory> triggerStrategy = new HashMap<>(4);
	static {
		triggerStrategy.put(TriggerConditionEnum.CONDITION_3.getCode(), SpringUtil.getBean(Condition3Handler.class));
		triggerStrategy.put(TriggerConditionEnum.CONDITION_6.getCode(), SpringUtil.getBean(Condition6And7And8Handler.class));
		triggerStrategy.put(TriggerConditionEnum.CONDITION_7.getCode(), SpringUtil.getBean(Condition6And7And8Handler.class));
		triggerStrategy.put(TriggerConditionEnum.CONDITION_8.getCode(), SpringUtil.getBean(Condition6And7And8Handler.class));
		triggerStrategy.put(TriggerConditionEnum.CONDITION_9.getCode(), SpringUtil.getBean(Condition9Handler.class));
		triggerStrategy.put(TriggerConditionEnum.CONDITION_10.getCode(), SpringUtil.getBean(Condition10And11Handler.class));
		triggerStrategy.put(TriggerConditionEnum.CONDITION_11.getCode(), SpringUtil.getBean(Condition10And11Handler.class));
	}

	public static TriggerConditionFactory get(Integer triggerConditionCode) {
		if (triggerStrategy.containsKey(triggerConditionCode)) {
			return triggerStrategy.get(triggerConditionCode);
		}
		return SpringUtil.getBean(DefaultHandler.class);
	}
}
